package com.bazaaroid.server.gae.api.resources.partner;

import java.util.List;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;

import com.bazaaroid.server.gae.core.dao.partner.DiscountDAO;
import com.bazaaroid.server.gae.core.dto.partner.ActiveDiscountsDTO;
import com.bazaaroid.server.gae.core.dto.partner.AllEntitiesDTO;
import com.bazaaroid.server.gae.core.dto.partner.AllEntitiesDTO.DiscountsDTO;
import com.bazaaroid.server.gae.core.ioc.GuiceFactory;
import com.bazaaroid.server.gae.core.persistence.model.partner.Discount;

@Path("/discount/")
public class DiscountResource {

	@GET
	@Produces( { "application/xml", "application/json" })
	@Path("/active/")
	public ActiveDiscountsDTO findActiveDiscounts() {
		DiscountDAO discountDAO = GuiceFactory.getInjector()
			.getInstance(DiscountDAO.class);
		List<Discount> discounts = discountDAO.findActiveDiscounts();
		return new ActiveDiscountsDTO(discounts);
	}

	@GET
	@Produces( { "application/xml", "application/json" })
	@Path("/all/")
	public DiscountsDTO getAllDiscounts() {
		DiscountDAO discountDAO = GuiceFactory.getInjector()
			.getInstance(DiscountDAO.class);
		List<Discount> discounts = discountDAO.getAll();
		return new AllEntitiesDTO.DiscountsDTO(discounts);
	}
}
